require('./index.scss');
var Config = require('common/config');
var Tool = require('common/tool');
var subMenuList = require('../tradeSubMenu');
require('comp/tab');
require('comp/sel');
require('comp/select');
require('comp/dialog');
var page ;

var vm = avalon.define({
    $id: 'reportTrade',
    lang: _language=='zh' ? 'CN':'TW',
    tabList:{
        active:0,
        list:subMenuList
    },
    accountInfo:'',
    platformName:'',
    /* 账号列表 */
    accountDropdown:{
        checkedItem:'',
        model:'',
        list:[],
        changefn:function(el){
            vm.platformName = el.platformName;
            page.submit();
        }
    },
    /* 日期列表 */
    dateDropdown:{
        checkedItem:'',
        model:'',
        list:[{
            val:"1",
            text:"当日",
        },{
            val:"2",
            text:"最近一周",
        },{
            val:"3",
            text:"最近一个月",
        },{
            val:"4",
            text:"最近三个月",
        }],
        changefn:function(el){
            vm.filterData.defaultETime = latelyDate(0);
            switch(el.val){
                case '1':
                    vm.filterData.defaultbTime = latelyDate(0);
                    break;
                case '2':
                    vm.filterData.defaultbTime = latelyDate(6);
                    break;
                case '3':
                    vm.filterData.defaultbTime = latelyMonth(1);
                    break;
                case '4':
                    vm.filterData.defaultbTime = latelyMonth(3);
                    break;
            }
            page.submit();
        }
    },
    /* 状态列表 */
    statusData:{
        checked:'',
        checkedText:'所有',
        list:[{
            val:"",
            text:"所有",
        },{
            val:"WITHDRAWAL_SUCCESS",
            text:"成功",
        },{
            val:"API_ERROR",
            text:"失败",
        },{
            val:"REJECTED",
            text:"已取消",
        },{
            val:"NOT_APPLICABLE",
            text:"不适用",
        }],
        changefn:function(){}
    },
    /* 查询条件 */
    filterData:{
        show:true,
        orderNo:false,
        defaultbTime:'',
        defaultETime:'',
    },
    /* 查询结果的列表 */
    tb:{
        loading:'',
        totalPage:'',
        curr:1,                         //当前页码
        pageSize:20,                    //当前显示条数
        errMsg:'',
        jump:function(obj){
            if( obj.curr!=vm.tb.curr ){
                vm.tb.curr = obj.curr;
                page.submit();
            }
        },
        thList:[
            {label:'申请编号',text:function(v){
                return '<a href="javascript:;" class="pno" data-pno="'+v.pno+'">'+v.pno+'</a>';
            }},
            {label:'取款金额',text:function(v){
                return Number(v.transAmount).toFixed(2);
            }},
            {label:'申请时间',text:function(v){
                return Tool.timeZone(v.createDate);
            }},
            {label:'状态',text:"stateName"},
            {label:'更新时间',text:function(v){
                return v.withdrawalSettleTime ? Tool.timeZone(v.withdrawalSettleTime) : Tool.timeZone(v.updateDate);
            }}
        ],
        list:''
    },
});

vm.$watch('onReady',function(){
    page = new PageModel();
    window['vm'] = vm;
});


function PageModel(){
    this.queryInfo();
    
}

// 获取取款页面信息
PageModel.prototype.queryInfo = function(){
    var that = this;
    vm.queryLoad = true;
    Tool.ajax('/recode').done(function(res){
        vm.queryLoad = false;
        var data = res.data,
            accTradeInfoList = data.accountInfo.accTradeInfoList;
        accTradeInfoList.forEach(function(v) {
            v.text = v.accountNo + '['+ v.platformName +']'
        });
        vm.accountInfo = data.accountInfo;
        vm.accountDropdown.list = accTradeInfoList;

    });
}
